package org.xlp.auto.create;

import org.xlp.utils.XLPArrayUtil;
import org.xlp.utils.XLPStringUtil;

import java.util.Arrays;

/**
 * Description: dao, service及实现java文件自动创建抽象类
 * <br/>date: 2023/12/4 17:06
 *
 * @version 1.0
 * @author: xlp
 */
public abstract class AbstractGroupAutoCreator extends AbstractAutoCreator{
    /**
     * 对应的impl 父类名称
     */
    private String supperClassNameForImpl;

    /**
     * 对应的impl 所需实现接口名称
     */
    private String[] interfaceNamesForImpl;

    /**
     * 对应的impl java文件类类型
     */
    private ClassType classTypeForImpl = ClassType.CLASS;

    public AbstractGroupAutoCreator() {
        super();
    }

    /**
     * 构造函数
     *
     * @param abstractAutoCreator
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public AbstractGroupAutoCreator(AbstractAutoCreator abstractAutoCreator) {
        super(abstractAutoCreator);
    }

    public String getSupperClassNameForImpl() {
        return supperClassNameForImpl;
    }

    public void setSupperClassNameForImpl(String supperClassNameForImpl) {
        this.supperClassNameForImpl = supperClassNameForImpl;
    }

    public String[] getInterfaceNamesForImpl() {
        return interfaceNamesForImpl;
    }

    public void setInterfaceNamesForImpl(String[] interfaceNamesForImpl) {
        this.interfaceNamesForImpl = interfaceNamesForImpl;
    }

    public ClassType getClassTypeForImpl() {
        return classTypeForImpl;
    }

    public void setClassTypeForImpl(ClassType classTypeForImpl) {
        this.classTypeForImpl = classTypeForImpl;
    }

    /**
     * 添加要实现的接口名称
     * @param interfaceName
     */
    public void addInterfaceNameForImpl(String interfaceName){
        if (XLPStringUtil.isEmpty(interfaceName)) return;

        if (XLPArrayUtil.isEmpty(interfaceNamesForImpl)){
            interfaceNamesForImpl = new String[]{interfaceName};
        } else {
            int len = interfaceNamesForImpl.length;
            interfaceNamesForImpl = Arrays.copyOf(interfaceNamesForImpl, len + 1);
            interfaceNamesForImpl[len] = interfaceName;
        }
    }
}
